<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

  <script>
    // 简单实现ajax
    const getData = function (url) {
      return new Promise(function (resolve, reject) {
        const handler = function () {
          if (this.readyState !== 4) {
            return;
          }
          if (this.status === 200) {
            resolve(this.response);
          } else {
            reject(new Error(this.statusText));
          }
        }

        const client = new XMLHttpRequest();
        client.open('GET', url);
        client.responseType = 'json';
        client.setRequestHeader('Accept', 'application/json');
        client.onreadystatechange = handler;
        client.send();

      })
    }

    getData('./data/data.json').then((data) => {
      console.log(data);
    }).catch((error) => {
      console.log(error);
    })
  </script>

</head>
<body>
  
</body>
</html>